home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
mac
/
files
/
dsp
/
56000tar.z
/
56000tar
/
56000
/
lattice
/
latfir1.hlp
< prev
next >
Wrap
Text File
|
1992-04-28
|
6KB
|
147 lines
Name: LATFIR1.ASM
Type: Assembler Macro
Version: 1.0
Last Change: 8-Aug-86
Description: Lattice FIR Filter Assembler Macro
This macro implements a lattice fir filter using reflection coefficients.
BACKGROUND
The basic section of a FIR lattice filter is shown in Figure 1.
>-------------------------------(+)----------->
f[j-1](n) \ ^ f[j](n)
\ /
\ k[j]
\ /
/
/ k[j]
/ \
/ v
>------1/z----------------------(+)----------->
b[j-1](n) b[j-1](n-1) b[j](n)
Figure 1
The reference [j] indicates the jth stage and the reference
(n) indicates the sample time. The equations for a filter
section are:
f[j](n)= f[j-1](n) + k[j]*b[j-1](n-1)
b[j](n)= b[j-1](n-1) + k[j]*f[j-1](n)
The signals f(n) and b(n) are commonly referred to as the
forward and backward prediction residuals respectively.
IMPLEMENTATION
A third order lattice FIR filter is shown in Figure 2.
T
|--->----->---(+)-->----->----(+)-->----->----(+)----> B (out)
| | ^ | ^ | ^
| | / | / | /
| \ k1 \ k2 \ k3
^ \ / \ / \ /
| / / /
B >--| /\ /\ /\
(in) | / \ / \ / \
v / k1 / k2 / k3
| | \ | \ | \
| | v | v | v
|- 1/z ---->--(+)- 1/z ---->--(+)- 1/z ---->--(+)-----
S1 S2 S3 Sx
Figure 2
For the filter shown, the pointers R0 and R4 are initialized
to point to the buffers as shown:
R0 R4
| |
v v
x: S1 S2 S3 Sx y: k1 k2 k3 kx
M0=3 (mod 4) M4=3 (mod 4)
The register R0 is initialized to point to the start of the
state variable buffer and R4 is initialized to point to the
first k coefficient of the filter. The modulo registers are
set to the number of coefficients in the filter (in this
example there are three). Note that the modulo storage area
is equal to the number of filter coefficients+1.
The input sample is put in the B register and then the filter
macro is called. The result of the filtering operation is in
B. The state 'sx' is an unused state which aids calculation
efficiency. (Actually, the value sx after a sample is
filtered is the output of the lower leg of the filter.) The
reflection coefficient 'kx' is an unused dummy value.
To use the filter, it is assumed the registers R0, R4, M0 and
M4 have been properly initialized. The input sample is put in
register B and the filter is called as:
latfir order ;call fir lattice filter
where 'latfir' is the macro name and 'order' is the number of
k coefficients.
FILTER OPERATION
The filter operation can be described (refer to Figure 2 and
the macro 'latfir1' in the DSPLIB):
1. The input sample is in register B. This input sample will
be the first state S1 at the next sample time and will
initialize the T value.
2. The first MOVE instruction saves the input sample to be
the first state S1 for the next sample and increments the
pointer R0 to the next state. The first k coefficient k1
is loaded into y0 and the pointer R4 is incremented to
point to the next coefficient.
3. The loop will make as many passes of the filter kernel as
there are coefficients in the filter.
4. The old state S1 is loaded into accumulator A so that the
the bottom b[j](n) can be computed (see Figure 1). The
current value of T (in register B) is moved into a product
register so it can be multiplied by the k coefficient.
5. The value b[j](n) is now computed by the first MAC. The T
value in Y1 is multiplied by the k coefficient in Y0 and
added to the value of the previous state (A). This value
will be the value of S2 for the next sample time. The
value in register A (the state value) is simultaneously
copied into product register X0 so it can be multiplied by
k in the next instruction.
6. The state (X0) is now multiplied by the k coefficient (Y0)
and added to the old value of T to get the new value of T.
Simultaneously, the new state variable (A) is saved and
the next k coefficient is obtained. The pointers R0 and
R4 are both incremented to point to the next state and
coefficient respectively.
7. Three passes of this loop are made. The first state
needed for the second sample is currently saved at the
first location of the state buffer with the other states
calculated by the loop saved in consecutive locations.
The last state that the loop calculates (Sx) is not needed
for the next sample time.
8. The result is rounded and the pointer to the state buffer
is backed up by one. This points the state buffer to the
unused state (Sx) so that the next sample is saved over
the unused state. Note that the initial MOVE increments
the pointer to the k's by one and the loop increments the
pointer three times. In order to have the pointer to the
k's pointing to the first coefficient (k1), the modulo on
the k pointer is four.
The benchmarks for this filter are: 7 instructions, 3N+5
instruction cycles, 2 stack locations.
An example of how to use this macro is in the DSPLIB in the
file LATFIR1T.ASM.